package com.group3.utils;

import com.group3.exception.ExceptionEnum;

/**
 * ResultUtil
 *
 * @author HY
 * 2021/06/10 15:45
 **/


public class ResultUtil {


    public static Result success(){

        return success(200, "操作成功", null, 0);
    }

    public static Result success(String msg){

        return success(200, msg, null, 0);
    }

    public static Result success(Object object){

        return success(200, "查询成功", object, 0);
    }

    public static Result success(String msg, Object object){

        return success(200, msg, object, 0);
    }

    public static Result success(String msg, Object object, long count){

        return success(200, msg, object, count);
    }

    public static Result success(Object object, long count){

        return success(200, "操作成功", object, count);
    }

    private static Result success(int code, String message, Object object, long count){

        Result result = new Result();
        result.setCode(code);
        result.setMsg(message);
        result.setData(object);
        result.setCount(count);

        return result;
    }

    public static Result error(){

        Result result = new Result();
        result.setCode(201);
        result.setMsg("操作失败");

        return result;
    }

    public static Result error(String message){

        Result result = new Result();
        result.setCode(201);
        result.setMsg(message);

        return result;
    }

    public static Result error(int code, String message){

        Result result = new Result();
        result.setCode(code);
        result.setMsg(message);

        return result;
    }

    public static Result error(ExceptionEnum exceptionEnum){

        Result result = new Result();
        result.setCode(exceptionEnum.getCode());
        result.setMsg(exceptionEnum.getMsg());

        return result;
    }
}
